package com.bdzl.ecs.controller;

import com.bdzl.ecs.service.ContractTmplObjService;
import com.bdzl.pub.controller.BaseController;
import com.bdzl.pub.entity.loan.ContractTmplObjDO;
import com.bdzl.pub.util.param.PageUtils;
import com.bdzl.pub.util.param.Query;
import com.bdzl.pub.util.param.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;


/**
 * 电子合同模板与签署对象关系表
 *
 * @author yangyicai
 * @email yangyicai@foxmail.com
 * @date 2021-03-23 14:00:09
 */

@Controller
@RequestMapping("/bdzl/contractTmplObj")
public class ContractTmplObjController extends BaseController {
	@Autowired
	private ContractTmplObjService contractTmplObjService;

	@GetMapping()
	String ContractTmplObj(){
	    return "bdzl/contractTmplObj/contractTmplObj";
	}

	@ResponseBody
	@GetMapping("/list")
	public PageUtils list(@RequestParam Map<String, Object> params){
		//查询列表数据
        Query query = new Query(params);
		List<ContractTmplObjDO> contractTmplObjList = contractTmplObjService.list(query);
		int total = contractTmplObjService.count(query);
		PageUtils pageUtils = new PageUtils(contractTmplObjList, total);
		return pageUtils;
	}

	@GetMapping("/add")
	String add(){
	    return "bdzl/contractTmplObj/add";
	}

	@GetMapping("/edit/{ctoId}")
	String edit(@PathVariable("ctoId") Integer ctoId,Model model){
		ContractTmplObjDO contractTmplObj = contractTmplObjService.get(ctoId);
		model.addAttribute("contractTmplObj", contractTmplObj);
	    return "bdzl/contractTmplObj/edit";
	}

	/**
	 * 保存
	 */
	@ResponseBody
	@PostMapping("/save")
	public R save( ContractTmplObjDO contractTmplObj){
		if(contractTmplObjService.save(contractTmplObj)>0){
			return R.ok();
		}
		return R.error();
	}
	/**
	 * 修改
	 */
	@ResponseBody
	@RequestMapping("/update")
	public R update( ContractTmplObjDO contractTmplObj){
		contractTmplObjService.update(contractTmplObj);
		return R.ok();
	}

	/**
	 * 删除
	 */
	@PostMapping( "/remove")
	@ResponseBody
	public R remove( Integer ctoId){
		if(contractTmplObjService.remove(ctoId)>0){
		return R.ok();
		}
		return R.error();
	}

	/**
	 * 删除
	 */
	@PostMapping( "/batchRemove")
	@ResponseBody
	public R remove(@RequestParam("ids[]") Integer[] ctoIds){
		contractTmplObjService.batchRemove(ctoIds);
		return R.ok();
	}

}
